<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Spring Security FAQ :: Spring Security</title>
<link rel="canonical" href="../../../servlet/appendix/faq.html">
<link rel="prev" href="namespace/websocket.html">
<link rel="next" href="../../reactive/index.html">
<meta name="generator" content="Antora 3.0.0">
<link rel="stylesheet" href="../../../_/css/site.css">
<link href="../../../_/img/favicon.ico" rel='shortcut icon' type='image/vnd.microsoft.icon'>
<link rel="stylesheet" href="../../../_/css/vendor/docsearch.min.css">

<script>var uiRootPath = '../../../_'</script>
</head>
<body class="article">
<header class="header">
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="https://spring.io">
<img id="springlogo" class="block" src="../../../_/img/spring-logo.svg" alt="Spring">
</a>
<button class="navbar-burger" data-target="topbar-nav">
<span></span>
<span></span>
<span></span>
</button>
</div>
<div id="topbar-nav" class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="faq.html#">Why Spring</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="https://spring.io/why-spring">Overview</a>
<a class="navbar-item" href="https://spring.io/microservices">Microservices</a>
<a class="navbar-item" href="https://spring.io/reactive">Reactive</a>
<a class="navbar-item" href="https://spring.io/event-driven">Event Driven</a>
<a class="navbar-item" href="https://spring.io/cloud">Cloud</a>
<a class="navbar-item" href="https://spring.io/web-applications">Web Applications</a>
<a class="navbar-item" href="https://spring.io/serverless">Serverless</a>
<a class="navbar-item" href="https://spring.io/batch">Batch</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="faq.html#">Learn</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="https://spring.io/learn">Overview</a>
<a class="navbar-item" href="https://spring.io/quickstart">Quickstart</a>
<a class="navbar-item" href="https://spring.io/guides">Guides</a>
<a class="navbar-item" href="https://spring.io/blog">Blog</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="faq.html#">Projects</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="https://spring.io/projects">Overview</a>
<a class="navbar-item" href="https://spring.io/projects/spring-boot">Spring Boot</a>
<a class="navbar-item" href="https://spring.io/projects/spring-framework">Spring Framework</a>
<a class="navbar-item" href="https://spring.io/projects/spring-cloud">Spring Cloud</a>
<a class="navbar-item" href="https://spring.io/projects/spring-cloud-dataflow">Spring Cloud Data Flow</a>
<a class="navbar-item" href="https://spring.io/projects/spring-data">Spring Data</a>
<a class="navbar-item" href="https://spring.io/projects/spring-integration">Spring Integration</a>
<a class="navbar-item" href="https://spring.io/projects/spring-batch">Spring Batch</a>
<a class="navbar-item" href="https://spring.io/projects/spring-security">Spring Security</a>
<a class="navbar-item navbar-item-special" href="https://spring.io/projects">View all projects</a>
<a class="navbar-item" href="https://spring.io/tools">Spring Tools 4</a>
<a class="navbar-item navbar-item-special-2" href="https://start.spring.io">Spring Initializr <svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><polyline points="15 10.94 15 15 1 15 1 1 5.06 1" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></polyline><polyline points="8.93 1 15 1 15 7.07" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></polyline><line x1="15" y1="1" x2="8" y2="8" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></line></svg></a>
</div>
</div>
<a class="navbar-item" href="https://spring.io/training">Training</a>
<a class="navbar-item" href="https://spring.io/support">Support</a>
<div class="navbar-item has-dropdown is-hoverable is-community">
<a class="navbar-link" href="faq.html#">Community</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="https://spring.io/community">Overview</a>
<a class="navbar-item" href="https://spring.io/events">Events</a>
<a class="navbar-item" href="https://spring.io/team">Team</a>
</div>
</div>
</div>
</div>
<div id="switch-theme">
<input type="checkbox" id="switch-theme-checkbox" />
<label for="switch-theme-checkbox">Dark Theme</label>
</div>
</nav>
</header>
<div class="body">
<div class="nav-container" data-component="ROOT" data-version="5.6.1">
<aside class="nav">
<div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu">
<h3 class="title"><a href="../../index.html">Spring Security</a></h3>
<ul class="nav-list">
<li class="nav-item" data-depth="0">
<ul class="nav-list">
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../index.html">Overview</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../prerequisites.html">Prerequisites</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../community.html">Community</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../whats-new.html">What&#8217;s New</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../getting-spring-security.html">Getting Spring Security</a>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../features/index.html">Features</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../features/authentication/index.html">Authentication</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/authentication/password-storage.html">Password Storage</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../features/exploits/index.html">Protection Against Exploits</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/exploits/csrf.html">CSRF</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/exploits/headers.html">HTTP Headers</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/exploits/http.html">HTTP Requests</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../features/integrations/index.html">Integrations</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/integrations/cryptography.html">Cryptography</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/integrations/data.html">Spring Data</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/integrations/concurrency.html">Java&#8217;s Concurrency APIs</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/integrations/jackson.html">Jackson</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../features/integrations/localization.html">Localization</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../modules.html">Project Modules</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../samples.html">Samples</a>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../index.html">Servlet Applications</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../getting-started.html">Getting Started</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../architecture.html">Architecture</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../authentication/index.html">Authentication</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/architecture.html">Authentication Architecture</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../authentication/passwords/index.html">Username/Password</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../authentication/passwords/input.html">Reading Username/Password</a>
<ul class="nav-list">
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/form.html">Form</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/basic.html">Basic</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/digest.html">Digest</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="4">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../authentication/passwords/storage.html">Password Storage</a>
<ul class="nav-list">
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/in-memory.html">In Memory</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/jdbc.html">JDBC</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/user-details.html">UserDetails</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/user-details-service.html">UserDetailsService</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/password-encoder.html">PasswordEncoder</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/dao-authentication-provider.html">DaoAuthenticationProvider</a>
</li>
<li class="nav-item" data-depth="5">
<a class="nav-link" href="../authentication/passwords/ldap.html">LDAP</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/session-management.html">Session Management</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/rememberme.html">Remember Me</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/openid.html">OpenID</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/anonymous.html">Anonymous</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/preauth.html">Pre-Authentication</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/jaas.html">JAAS</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/cas.html">CAS</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/x509.html">X509</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/runas.html">Run-As</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/logout.html">Logout</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authentication/events.html">Authentication Events</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../authorization/index.html">Authorization</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/architecture.html">Authorization Architecture</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/authorize-http-requests.html">Authorize HTTP Requests</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/authorize-requests.html">Authorize HTTP Requests with FilterSecurityInterceptor</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/expression-based.html">Expression-Based Access Control</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/secure-objects.html">Secure Object Implementations</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/method-security.html">Method Security</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../authorization/acls.html">Domain Object Security ACLs</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../oauth2/index.html">OAuth2</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../oauth2/login/index.html">OAuth2 Log In</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/login/core.html">Core Configuration</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/login/advanced.html">Advanced Configuration</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../oauth2/client/index.html">OAuth2 Client</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/client/core.html">Core Interfaces and Classes</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/client/authorization-grants.html">OAuth2 Authorization Grants</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/client/client-authentication.html">OAuth2 Client Authentication</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/client/authorized-clients.html">OAuth2 Authorized Clients</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../oauth2/resource-server/index.html">OAuth2 Resource Server</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/resource-server/jwt.html">JWT</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/resource-server/opaque-token.html">Opaque Token</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/resource-server/multitenancy.html">Multitenancy</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../oauth2/resource-server/bearer-tokens.html">Bearer Tokens</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../saml2/index.html">SAML2</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../saml2/login/index.html">SAML2 Log In</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../saml2/login/overview.html">SAML2 Log In Overview</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../saml2/login/authentication-requests.html">SAML2 Authentication Requests</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../saml2/login/authentication.html">SAML2 Authentication Responses</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../saml2/logout.html">SAML2 Logout</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../saml2/metadata.html">SAML2 Metadata</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../exploits/index.html">Protection Against Exploits</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../exploits/csrf.html">Cross Site Request Forgery (CSRF) for Servlet Environments</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../exploits/headers.html">Security HTTP Response Headers</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../exploits/http.html">HTTP</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../exploits/firewall.html">HttpFirewall</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../integrations/index.html">Integrations</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/concurrency.html">Concurrency</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/jackson.html">Jackson</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/localization.html">Localization</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/servlet-api.html">Servlet APIs</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/data.html">Spring Data</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/mvc.html">Spring MVC</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/websocket.html">WebSocket</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/cors.html">Spring&#8217;s CORS Support</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../integrations/jsp-taglibs.html">JSP Taglib</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Configuration</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../configuration/java.html">Java Configuration</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../configuration/kotlin.html">Kotlin Configuration</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../configuration/xml-namespace.html">Namespace Configuration</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../test/index.html">Testing</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../test/method.html">Method Security</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../test/mockmvc/index.html">MockMvc Support</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../test/mockmvc/setup.html">MockMvc Setup</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../test/mockmvc/request-post-processors.html">Security RequestPostProcessors</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../test/mockmvc/authentication.html">Mocking Users</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../test/mockmvc/csrf.html">Mocking CSRF</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../test/mockmvc/form-login.html">Mocking Form Login</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../test/mockmvc/http-basic.html">Mocking HTTP Basic</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../test/mockmvc/oauth2.html">Mocking OAuth2</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../test/mockmvc/logout.html">Mocking Logout</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../test/mockmvc/request-builders.html">Security RequestBuilders</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../test/mockmvc/result-matchers.html">Security ResultMatchers</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../test/mockmvc/result-handlers.html">Security ResultHandlers</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="index.html">Appendix</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="database-schema.html">Database Schemas</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="namespace/index.html">XML Namespace</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="namespace/authentication-manager.html">Authentication Services</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="namespace/http.html">Web Security</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="namespace/method-security.html">Method Security</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="namespace/ldap.html">LDAP Security</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="namespace/websocket.html">WebSocket Security</a>
</li>
</ul>
</li>
<li class="nav-item is-current-page" data-depth="3">
<a class="nav-link" href="faq.html">FAQ</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/index.html">Reactive Applications</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../reactive/getting-started.html">Getting Started</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Authentication</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/authentication/x509.html">X.509 Authentication</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/authentication/logout.html">Logout</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Authorization</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/authorization/method.html">EnableReactiveMethodSecurity</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/oauth2/index.html">OAuth2</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/oauth2/login/index.html">OAuth2 Log In</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/login/core.html">Core Configuration</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/login/advanced.html">Advanced Configuration</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/oauth2/client/index.html">OAuth2 Client</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/client/core.html">Core Interfaces and Classes</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/client/authorization-grants.html">OAuth2 Authorization Grants</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/client/client-authentication.html">OAuth2 Client Authentication</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/client/authorized-clients.html">OAuth2 Authorized Clients</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/oauth2/resource-server/index.html">OAuth2 Resource Server</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/resource-server/jwt.html">JWT</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/resource-server/opaque-token.html">Opaque Token</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/resource-server/multitenancy.html">Multitenancy</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/oauth2/resource-server/bearer-tokens.html">Bearer Tokens</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/exploits/index.html">Protection Against Exploits</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/exploits/csrf.html">CSRF</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/exploits/headers.html">Headers</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/exploits/http.html">HTTP Requests</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Integrations</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/integrations/cors.html">CORS</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/integrations/rsocket.html">RSocket</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/test/index.html">Testing</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../reactive/test/method.html">Testing Method Security</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../reactive/test/web/index.html">Testing Web Security</a>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/test/web/setup.html">WebTestClient Setup</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/test/web/authentication.html">Testing Authentication</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/test/web/csrf.html">Testing CSRF</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../reactive/test/web/oauth2.html">Testing OAuth 2.0</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../reactive/configuration/webflux.html">WebFlux Security</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
<div class="context">
<span class="title">Spring Security</span>
<span class="version">5.6.1</span>
</div>
<ul class="components">
<li class="component is-current">
<a class="title" href="../../../index.html">Spring Security</a>
<ul class="versions">
<li class="version">
<a href="../../../6.0/index.html">6.0.0-SNAPSHOT</a>
</li>
<li class="version">
<a href="../../../6.0.0-M3/index.html">6.0.0-M3</a>
</li>
<li class="version">
<a href="../../../6.0.0-M2/index.html">6.0.0-M2</a>
</li>
<li class="version">
<a href="../../../6.0.0-M1/index.html">6.0.0-M1</a>
</li>
<li class="version">
<a href="../../../5.7/index.html">5.7.0-SNAPSHOT</a>
</li>
<li class="version">
<a href="../../../5.7.0-RC1/index.html">5.7.0-RC1</a>
</li>
<li class="version">
<a href="../../../5.7.0-M3/index.html">5.7.0-M3</a>
</li>
<li class="version">
<a href="../../../5.7.0-M2/index.html">5.7.0-M2</a>
</li>
<li class="version">
<a href="../../../5.7.0-M1/index.html">5.7.0-M1</a>
</li>
<li class="version">
<a href="../../../5.6.4/index.html">5.6.4-SNAPSHOT</a>
</li>
<li class="version is-latest">
<a href="../../../index.html">5.6.3</a>
</li>
<li class="version">
<a href="../../../5.6.2/index.html">5.6.2</a>
</li>
<li class="version is-current">
<a href="../../index.html">5.6.1</a>
</li>
<li class="version">
<a href="../../../5.6.0/index.html">5.6.0</a>
</li>
<li class="version">
<a href="../../../5.6.0-RC1/index.html">5.6.0-RC1</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
<nav class="breadcrumbs" aria-label="breadcrumbs">
<ul>
<li><a href="../../index.html">Spring Security</a></li>
<li><a href="../index.html">Servlet Applications</a></li>
<li><a href="index.html">Appendix</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul>
</nav>
<div class="search">
<input id="search-input" type="text" placeholder="Search docs">
</div>
<div class="page-versions">
<button class="version-menu-toggle" title="Show other versions of page">5.6.1</button>
<div class="version-menu">
<a class="version" href="../../../6.0/servlet/appendix/faq.html">6.0.0-SNAPSHOT</a>
<a class="version" href="../../../6.0.0-M3/servlet/appendix/faq.html">6.0.0-M3</a>
<a class="version" href="../../../6.0.0-M2/servlet/appendix/faq.html">6.0.0-M2</a>
<a class="version" href="../../../6.0.0-M1/servlet/appendix/faq.html">6.0.0-M1</a>
<a class="version" href="../../../5.7/servlet/appendix/faq.html">5.7.0-SNAPSHOT</a>
<a class="version" href="../../../5.7.0-RC1/servlet/appendix/faq.html">5.7.0-RC1</a>
<a class="version" href="../../../5.7.0-M3/servlet/appendix/faq.html">5.7.0-M3</a>
<a class="version" href="../../../5.7.0-M2/servlet/appendix/faq.html">5.7.0-M2</a>
<a class="version" href="../../../5.7.0-M1/servlet/appendix/faq.html">5.7.0-M1</a>
<a class="version" href="../../../5.6.4/servlet/appendix/faq.html">5.6.4-SNAPSHOT</a>
<a class="version" href="../../../servlet/appendix/faq.html">5.6.3</a>
<a class="version" href="../../../5.6.2/servlet/appendix/faq.html">5.6.2</a>
<a class="version is-current" href="faq.html">5.6.1</a>
<a class="version" href="../../../5.6.0/servlet/appendix/faq.html">5.6.0</a>
<a class="version" href="../../../5.6.0-RC1/servlet/appendix/faq.html">5.6.0-RC1</a>
</div>
</div>
 <div class="edit-this-page"><a href="https://github.com/spring-projects/spring-security/blob/5.6.1/docs/modules/ROOT/pages/servlet/appendix/faq.adoc">Edit this Page</a></div>
</div>
<div class="content">
<aside class="toc sidebar" data-title="Contents" data-levels="2">
<div class="toc-menu"></div>
</aside>
<article class="doc">
<div class="admonitionblock important">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p> For the latest stable version, please use <a href="../../../servlet/appendix/faq.html">Spring Security 5.6.3</a>!</p>
</div>
</td>
</tr></tbody>
</table>
</div>
<h1 id="page-title" class="page">Spring Security FAQ</h1>
<div id="preamble">
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p><a href="faq.html#appendix-faq-general-questions">General Questions</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-common-problems">Common Problems</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-architecture">Spring Security Architecture Questions</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-howto">Common "Howto" Requests</a></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="appendix-faq-general-questions"><a class="anchor" href="faq.html#appendix-faq-general-questions"></a>General Questions</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="faq.html#appendix-faq-other-concerns">Will Spring Security take care of all my application security requirements?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-web-xml">Why not just use web.xml security?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-requirements">What Java and Spring Framework versions are required?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-start-simple">I&#8217;m new to Spring Security and I need to build an application that supports CAS single sign-on over HTTPS, while allowing Basic authentication locally for certain URLs, authenticating against multiple back end user information sources (LDAP and JDBC). I&#8217;ve copied some configuration files I found but it doesn&#8217;t work.</a></p>
</li>
</ol>
</div>
<div class="sect2">
<h3 id="appendix-faq-other-concerns"><a class="anchor" href="faq.html#appendix-faq-other-concerns"></a>Will Spring Security take care of all my application security requirements?</h3>
<div class="paragraph">
<p>Spring Security provides you with a very flexible framework for your authentication and authorization requirements, but there are many other considerations for building a secure application that are outside its scope.
Web applications are vulnerable to all kinds of attacks which you should be familiar with, preferably before you start development so you can design and code with them in mind from the beginning.
Check out the <a href="https://www.owasp.org/">OWASP web site</a> for information on the major issues facing web application developers and the countermeasures you can use against them.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-web-xml"><a class="anchor" href="faq.html#appendix-faq-web-xml"></a>Why not just use web.xml security?</h3>
<div class="paragraph">
<p>Let&#8217;s assume you&#8217;re developing an enterprise application based on Spring.
There are four security concerns you typically need to address: authentication, web request security, service layer security (i.e. your methods that implement business logic), and domain object instance security (i.e. different domain objects have different permissions). With these typical requirements in mind:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><em>Authentication</em>: The servlet specification provides an approach to authentication.
However, you will need to configure the container to perform authentication which typically requires editing of container-specific "realm" settings.
This makes a non-portable configuration, and if you need to write an actual Java class to implement the container&#8217;s authentication interface, it becomes even more non-portable.
With Spring Security you achieve complete portability - right down to the WAR level.
Also, Spring Security offers a choice of production-proven authentication providers and mechanisms, meaning you can switch your authentication approaches at deployment time.
This is particularly valuable for software vendors writing products that need to work in an unknown target environment.</p>
</li>
<li>
<p><em>Web request security:</em> The servlet specification provides an approach to secure your request URIs.
However, these URIs can only be expressed in the servlet specification&#8217;s own limited URI path format.
Spring Security provides a far more comprehensive approach.
For instance, you can use Ant paths or regular expressions, you can consider parts of the URI other than simply the requested page (e.g.
you can consider HTTP GET parameters) and you can implement your own runtime source of configuration data.
This means your web request security can be dynamically changed during the actual execution of your webapp.</p>
</li>
<li>
<p><em>Service layer and domain object security:</em> The absence of support in the servlet specification for services layer security or domain object instance security represent serious limitations for multi-tiered applications.
Typically developers either ignore these requirements, or implement security logic within their MVC controller code (or even worse, inside the views). There are serious disadvantages with this approach:</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><em>Separation of concerns:</em> Authorization is a crosscutting concern and should be implemented as such.
MVC controllers or views implementing authorization code makes it more difficult to test both the controller and authorization logic, more difficult to debug, and will often lead to code duplication.</p>
</li>
<li>
<p><em>Support for rich clients and web services:</em> If an additional client type must ultimately be supported, any authorization code embedded within the web layer is non-reusable.
It should be considered that Spring remoting exporters only export service layer beans (not MVC controllers). As such authorization logic needs to be located in the services layer to support a multitude of client types.</p>
</li>
<li>
<p><em>Layering issues:</em> An MVC controller or view is simply the incorrect architectural layer to implement authorization decisions concerning services layer methods or domain object instances.
Whilst the Principal may be passed to the services layer to enable it to make the authorization decision, doing so would introduce an additional argument on every services layer method.
A more elegant approach is to use a ThreadLocal to hold the Principal, although this would likely increase development time to a point where it would become more economical (on a cost-benefit basis) to simply use a dedicated security framework.</p>
</li>
<li>
<p><em>Authorisation code quality:</em> It is often said of web frameworks that they "make it easier to do the right things, and harder to do the wrong things". Security frameworks are the same, because they are designed in an abstract manner for a wide range of purposes.
Writing your own authorization code from scratch does not provide the "design check" a framework would offer, and in-house authorization code will typically lack the improvements that emerge from widespread deployment, peer review and new versions.</p>
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>For simple applications, servlet specification security may just be enough.
Although when considered within the context of web container portability, configuration requirements, limited web request security flexibility, and non-existent services layer and domain object instance security, it becomes clear why developers often look to alternative solutions.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-requirements"><a class="anchor" href="faq.html#appendix-faq-requirements"></a>What Java and Spring Framework versions are required?</h3>
<div class="paragraph">
<p>Spring Security 3.0 and 3.1 require at least JDK 1.5 and also require Spring 3.0.3 as a minimum.
Ideally you should be using the latest release versions to avoid problems.</p>
</div>
<div class="paragraph">
<p>Spring Security 2.0.x requires a minimum JDK version of 1.4 and is built against Spring 2.0.x.
It should also be compatible with applications using Spring 2.5.x.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-start-simple"><a class="anchor" href="faq.html#appendix-faq-start-simple"></a>I&#8217;m new to Spring Security and I need to build an application that supports CAS single sign-on over HTTPS, while allowing Basic authentication locally for certain URLs, authenticating against multiple back end user information sources (LDAP and JDBC). I&#8217;ve copied some configuration files I found but it doesn&#8217;t work.</h3>
<div class="paragraph">
<p>What could be wrong?</p>
</div>
<div class="paragraph">
<p>Or substitute an alternative complex scenario&#8230;&#8203;</p>
</div>
<div class="paragraph">
<p>Realistically, you need an understanding of the technologies you are intending to use before you can successfully build applications with them.
Security is complicated.
Setting up a simple configuration using a login form and some hard-coded users using Spring Security&#8217;s namespace is reasonably straightforward.
Moving to using a backed JDBC database is also easy enough.
But if you try and jump straight to a complicated deployment scenario like this you will almost certainly be frustrated.
There is a big jump in the learning curve required to set up systems like CAS, configure LDAP servers and install SSL certificates properly.
So you need to take things one step at a time.</p>
</div>
<div class="paragraph">
<p>From a Spring Security perspective, the first thing you should do is follow the "Getting Started" guide on the web site.
This will take you through a series of steps to get up and running and get some idea of how the framework operates.
If you are using other technologies which you aren&#8217;t familiar with then you should do some research and try to make sure you can use them in isolation before combining them in a complex system.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="appendix-faq-common-problems"><a class="anchor" href="faq.html#appendix-faq-common-problems"></a>Common Problems</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Authentication</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><a href="faq.html#appendix-faq-bad-credentials">When I try to log in, I get an error message that says "Bad Credentials". What&#8217;s wrong?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-login-loop">My application goes into an "endless loop" when I try to login, what&#8217;s going on?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-anon-access-denied">I get an exception with the message "Access is denied (user is anonymous);". What&#8217;s wrong?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-cached-secure-page">Why can I still see a secured page even after I&#8217;ve logged out of my application?</a></p>
</li>
<li>
<p><a href="faq.html#auth-exception-credentials-not-found">I get an exception with the message "An Authentication object was not found in the SecurityContext". What&#8217;s wrong?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-ldap-authentication">I can&#8217;t get LDAP authentication to work.</a></p>
</li>
</ol>
</div>
</li>
<li>
<p>Session Management</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><a href="faq.html#appendix-faq-concurrent-session-same-browser">I&#8217;m using Spring Security&#8217;s concurrent session control to prevent users from logging in more than once at a time.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-new-session-on-authentication">Why does the session Id change when I authenticate through Spring Security?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-tomcat-https-session">I&#8217;m using Tomcat (or some other servlet container) and have enabled HTTPS for my login page, switching back to HTTP afterwards.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-session-listener-missing">I&#8217;m trying to use the concurrent session-control support but it won&#8217;t let me log back in, even if I&#8217;m sure I&#8217;ve logged out and haven&#8217;t exceeded the allowed sessions.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-unwanted-session-creation">Spring Security is creating a session somewhere, even though I&#8217;ve configured it not to, by setting the create-session attribute to never.</a></p>
</li>
</ol>
</div>
</li>
<li>
<p>Miscellaneous</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><a href="faq.html#appendix-faq-forbidden-csrf">I get a 403 Forbidden when performing a POST</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-no-security-on-forward">I&#8217;m forwarding a request to another URL using the RequestDispatcher, but my security constraints aren&#8217;t being applied.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-method-security-in-web-context">I have added Spring Security&#8217;s &lt;global-method-security&gt; element to my application context but if I add security annotations to my Spring MVC controller beans (Struts actions etc.) then they don&#8217;t seem to have an effect.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-no-filters-no-context">I have a user who has definitely been authenticated, but when I try to access the SecurityContextHolder during some requests, the Authentication is null.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-method-security-with-taglib">The authorize JSP Tag doesn&#8217;t respect my method security annotations when using the URL attribute.</a></p>
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="sect2">
<h3 id="appendix-faq-bad-credentials"><a class="anchor" href="faq.html#appendix-faq-bad-credentials"></a>When I try to log in, I get an error message that says "Bad Credentials". What&#8217;s wrong?</h3>
<div class="paragraph">
<p>This means that authentication has failed.
It doesn&#8217;t say why, as it is good practice to avoid giving details which might help an attacker guess account names or passwords.</p>
</div>
<div class="paragraph">
<p>This also means that if you ask this question in the forum, you will not get an answer unless you provide additional information.
As with any issue you should check the output from the debug log, note any exception stacktraces and related messages.
Step through the code in a debugger to see where the authentication fails and why.
Write a test case which exercises your authentication configuration outside of the application.
More often than not, the failure is due to a difference in the password data stored in a database and that entered by the user.
If you are using hashed passwords, make sure the value stored in your database is <em>exactly</em> the same as the value produced by the <code>PasswordEncoder</code> configured in your application.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-login-loop"><a class="anchor" href="faq.html#appendix-faq-login-loop"></a>My application goes into an "endless loop" when I try to login, what&#8217;s going on?</h3>
<div class="paragraph">
<p>A common user problem with infinite loop and redirecting to the login page is caused by accidentally configuring the login page as a "secured" resource.
Make sure your configuration allows anonymous access to the login page, either by excluding it from the security filter chain or marking it as requiring ROLE_ANONYMOUS.</p>
</div>
<div class="paragraph">
<p>If your AccessDecisionManager includes an AuthenticatedVoter, you can use the attribute "IS_AUTHENTICATED_ANONYMOUSLY". This is automatically available if you are using the standard namespace configuration setup.</p>
</div>
<div class="paragraph">
<p>From Spring Security 2.0.1 onwards, when you are using namespace-based configuration, a check will be made on loading the application context and a warning message logged if your login page appears to be protected.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-anon-access-denied"><a class="anchor" href="faq.html#appendix-faq-anon-access-denied"></a>I get an exception with the message "Access is denied (user is anonymous);". What&#8217;s wrong?</h3>
<div class="paragraph">
<p>This is a debug level message which occurs the first time an anonymous user attempts to access a protected resource.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">DEBUG [ExceptionTranslationFilter] - Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.AccessDeniedException: Access is denied
at org.springframework.security.vote.AffirmativeBased.decide(AffirmativeBased.java:68)
at org.springframework.security.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:262)</code></pre>
</div>
</div>
<div class="paragraph">
<p>It is normal and shouldn&#8217;t be anything to worry about.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-cached-secure-page"><a class="anchor" href="faq.html#appendix-faq-cached-secure-page"></a>Why can I still see a secured page even after I&#8217;ve logged out of my application?</h3>
<div class="paragraph">
<p>The most common reason for this is that your browser has cached the page and you are seeing a copy which is being retrieved from the browsers cache.
Verify this by checking whether the browser is actually sending the request (check your server access logs, the debug log or use a suitable browser debugging plugin such as "Tamper Data" for Firefox). This has nothing to do with Spring Security and you should configure your application or server to set the appropriate <code>Cache-Control</code> response headers.
Note that SSL requests are never cached.</p>
</div>
</div>
<div class="sect2">
<h3 id="auth-exception-credentials-not-found"><a class="anchor" href="faq.html#auth-exception-credentials-not-found"></a>I get an exception with the message "An Authentication object was not found in the SecurityContext". What&#8217;s wrong?</h3>
<div class="paragraph">
<p>This is a another debug level message which occurs the first time an anonymous user attempts to access a protected resource, but when you do not have an <code>AnonymousAuthenticationFilter</code> in your filter chain configuration.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">DEBUG [ExceptionTranslationFilter] - Authentication exception occurred; redirecting to authentication entry point
org.springframework.security.AuthenticationCredentialsNotFoundException:
							An Authentication object was not found in the SecurityContext
at org.springframework.security.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:342)
at org.springframework.security.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:254)</code></pre>
</div>
</div>
<div class="paragraph">
<p>It is normal and shouldn&#8217;t be anything to worry about.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-ldap-authentication"><a class="anchor" href="faq.html#appendix-faq-ldap-authentication"></a>I can&#8217;t get LDAP authentication to work.</h3>
<div class="paragraph">
<p>What&#8217;s wrong with my configuration?</p>
</div>
<div class="paragraph">
<p>Note that the permissions for an LDAP directory often do not allow you to read the password for a user.
Hence it is often not possible to use the <a href="faq.html#appendix-faq-what-is-userdetailservice">What is a UserDetailsService and do I need one?</a> where Spring Security compares the stored password with the one submitted by the user.
The most common approach is to use LDAP "bind", which is one of the operations supported by <a href="https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol">the LDAP protocol</a>. With this approach, Spring Security validates the password by attempting to authenticate to the directory as the user.</p>
</div>
<div class="paragraph">
<p>The most common problem with LDAP authentication is a lack of knowledge of the directory server tree structure and configuration.
This will be different in different companies, so you have to find it out yourself.
Before adding a Spring Security LDAP configuration to an application, it&#8217;s a good idea to write a simple test using standard Java LDAP code (without Spring Security involved), and make sure you can get that to work first.
For example, to authenticate a user, you could use the following code:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock primary">
<div class="title">Java</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Test
public void ldapAuthenticationIsSuccessful() throws Exception {
		Hashtable&lt;String,String&gt; env = new Hashtable&lt;String,String&gt;();
		env.put(Context.SECURITY_AUTHENTICATION, "simple");
		env.put(Context.SECURITY_PRINCIPAL, "cn=joe,ou=users,dc=mycompany,dc=com");
		env.put(Context.PROVIDER_URL, "ldap://mycompany.com:389/dc=mycompany,dc=com");
		env.put(Context.SECURITY_CREDENTIALS, "joespassword");
		env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

		InitialLdapContext ctx = new InitialLdapContext(env, null);

}</code></pre>
</div>
</div>
<div class="listingblock secondary">
<div class="title">Kotlin</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-kotlin hljs" data-lang="kotlin">@Test
fun ldapAuthenticationIsSuccessful() {
    val env = Hashtable&lt;String, String&gt;()
    env[Context.SECURITY_AUTHENTICATION] = "simple"
    env[Context.SECURITY_PRINCIPAL] = "cn=joe,ou=users,dc=mycompany,dc=com"
    env[Context.PROVIDER_URL] = "ldap://mycompany.com:389/dc=mycompany,dc=com"
    env[Context.SECURITY_CREDENTIALS] = "joespassword"
    env[Context.INITIAL_CONTEXT_FACTORY] = "com.sun.jndi.ldap.LdapCtxFactory"
    val ctx = InitialLdapContext(env, null)
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_session_management"><a class="anchor" href="faq.html#_session_management"></a>Session Management</h3>
<div class="paragraph">
<p>Session management issues are a common source of forum questions.
If you are developing Java web applications, you should understand how the session is maintained between the servlet container and the user&#8217;s browser.
You should also understand the difference between secure and non-secure cookies and the implications of using HTTP/HTTPS and switching between the two.
Spring Security has nothing to do with maintaining the session or providing session identifiers.
This is entirely handled by the servlet container.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-concurrent-session-same-browser"><a class="anchor" href="faq.html#appendix-faq-concurrent-session-same-browser"></a>I&#8217;m using Spring Security&#8217;s concurrent session control to prevent users from logging in more than once at a time.</h3>
<div class="paragraph">
<p>When I open another browser window after logging in, it doesn&#8217;t stop me from logging in again.
Why can I log in more than once?</p>
</div>
<div class="paragraph">
<p>Browsers generally maintain a single session per browser instance.
You cannot have two separate sessions at once.
So if you log in again in another window or tab you are just reauthenticating in the same session.
The server doesn&#8217;t know anything about tabs, windows or browser instances.
All it sees are HTTP requests and it ties those to a particular session according to the value of the JSESSIONID cookie that they contain.
When a user authenticates during a session, Spring Security&#8217;s concurrent session control checks the number of <em>other authenticated sessions</em> that they have.
If they are already authenticated with the same session, then re-authenticating will have no effect.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-new-session-on-authentication"><a class="anchor" href="faq.html#appendix-faq-new-session-on-authentication"></a>Why does the session Id change when I authenticate through Spring Security?</h3>
<div class="paragraph">
<p>With the default configuration, Spring Security changes the session ID when the user authenticates.
If you&#8217;re using a Servlet 3.1 or newer container, the session ID is simply changed.
If you&#8217;re using an older container, Spring Security invalidates the existing session, creates a new session, and transfers the session data to the new session.
Changing the session identifier in this manner prevents"session-fixation" attacks.
You can find more about this online and in the reference manual.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-tomcat-https-session"><a class="anchor" href="faq.html#appendix-faq-tomcat-https-session"></a>I&#8217;m using Tomcat (or some other servlet container) and have enabled HTTPS for my login page, switching back to HTTP afterwards.</h3>
<div class="paragraph">
<p>It doesn&#8217;t work - I just end up back at the login page after authenticating.</p>
</div>
<div class="paragraph">
<p>This happens because sessions created under HTTPS, for which the session cookie is marked as "secure", cannot subsequently be used under HTTP. The browser will not send the cookie back to the server and any session state will be lost (including the security context information). Starting a session in HTTP first should work as the session cookie won&#8217;t be marked as secure.
However, Spring Security&#8217;s <a href="https://docs.spring.io/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-session-fixation">Session Fixation Protection</a> can interfere with this because it results in a new session ID cookie being sent back to the user&#8217;s browser, usually with the secure flag.
To get around this, you can disable session fixation protection, but in newer Servlet containers you can also configure session cookies to never use the secure flag.
Note that switching between HTTP and HTTPS is not a good idea in general, as any application which uses HTTP at all is vulnerable to man-in-the-middle attacks.
To be truly secure, the user should begin accessing your site in HTTPS and continue using it until they log out.
Even clicking on an HTTPS link from a page accessed over HTTP is potentially risky.
If you need more convincing, check out a tool like <a href="https://github.com/moxie0/sslstrip/">sslstrip</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="_im_not_switching_between_http_and_https_but_my_session_is_still_getting_lost"><a class="anchor" href="faq.html#_im_not_switching_between_http_and_https_but_my_session_is_still_getting_lost"></a>I&#8217;m not switching between HTTP and HTTPS but my session is still getting lost</h3>
<div class="paragraph">
<p>Sessions are maintained either by exchanging a session cookie or by adding a <code>jsessionid</code> parameter to URLs (this happens automatically if you are using JSTL to output URLs, or if you call <code>HttpServletResponse.encodeUrl</code> on URLs (before a redirect, for example). If clients have cookies disabled, and you are not rewriting URLs to include the <code>jsessionid</code>, then the session will be lost.
Note that the use of cookies is preferred for security reasons, as it does not expose the session information in the URL.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-session-listener-missing"><a class="anchor" href="faq.html#appendix-faq-session-listener-missing"></a>I&#8217;m trying to use the concurrent session-control support but it won&#8217;t let me log back in, even if I&#8217;m sure I&#8217;ve logged out and haven&#8217;t exceeded the allowed sessions.</h3>
<div class="paragraph">
<p>Make sure you have added the listener to your web.xml file.
It is essential to make sure that the Spring Security session registry is notified when a session is destroyed.
Without it, the session information will not be removed from the registry.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml">&lt;listener&gt;
		&lt;listener-class&gt;org.springframework.security.web.session.HttpSessionEventPublisher&lt;/listener-class&gt;
&lt;/listener&gt;</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-unwanted-session-creation"><a class="anchor" href="faq.html#appendix-faq-unwanted-session-creation"></a>Spring Security is creating a session somewhere, even though I&#8217;ve configured it not to, by setting the create-session attribute to never.</h3>
<div class="paragraph">
<p>This usually means that the user&#8217;s application is creating a session somewhere, but that they aren&#8217;t aware of it.
The most common culprit is a JSP. Many people aren&#8217;t aware that JSPs create sessions by default.
To prevent a JSP from creating a session, add the directive <code>&lt;%@ page session="false" %&gt;</code> to the top of the page.</p>
</div>
<div class="paragraph">
<p>If you are having trouble working out where a session is being created, you can add some debugging code to track down the location(s). One way to do this would be to add a <code>javax.servlet.http.HttpSessionListener</code> to your application, which calls <code>Thread.dumpStack()</code> in the <code>sessionCreated</code> method.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-forbidden-csrf"><a class="anchor" href="faq.html#appendix-faq-forbidden-csrf"></a>I get a 403 Forbidden when performing a POST</h3>
<div class="paragraph">
<p>If an HTTP 403 Forbidden is returned for HTTP POST, but works for HTTP GET then the issue is most likely related to <a href="https://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#csrf">CSRF</a>. Either provide the CSRF Token or disable CSRF protection (not recommended).</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-no-security-on-forward"><a class="anchor" href="faq.html#appendix-faq-no-security-on-forward"></a>I&#8217;m forwarding a request to another URL using the RequestDispatcher, but my security constraints aren&#8217;t being applied.</h3>
<div class="paragraph">
<p>Filters are not applied by default to forwards or includes.
If you really want the security filters to be applied to forwards and/or includes, then you have to configure these explicitly in your web.xml using the &lt;dispatcher&gt; element, a child element of &lt;filter-mapping&gt;.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-method-security-in-web-context"><a class="anchor" href="faq.html#appendix-faq-method-security-in-web-context"></a>I have added Spring Security&#8217;s &lt;global-method-security&gt; element to my application context but if I add security annotations to my Spring MVC controller beans (Struts actions etc.) then they don&#8217;t seem to have an effect.</h3>
<div class="paragraph">
<p>In a Spring web application, the application context which holds the Spring MVC beans for the dispatcher servlet is often separate from the main application context.
It is often defined in a file called <code>myapp-servlet.xml</code>, where "myapp" is the name assigned to the Spring <code>DispatcherServlet</code> in <code>web.xml</code>. An application can have multiple <code>DispatcherServlet</code>s, each with its own isolated application context.
The beans in these "child" contexts are not visible to the rest of the application.
The"parent" application context is loaded by the <code>ContextLoaderListener</code> you define in your <code>web.xml</code> and is visible to all the child contexts.
This parent context is usually where you define your security configuration, including the <code>&lt;global-method-security&gt;</code> element). As a result any security constraints applied to methods in these web beans will not be enforced, since the beans cannot be seen from the <code>DispatcherServlet</code> context.
You need to either move the <code>&lt;global-method-security&gt;</code> declaration to the web context or moved the beans you want secured into the main application context.</p>
</div>
<div class="paragraph">
<p>Generally we would recommend applying method security at the service layer rather than on individual web controllers.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-no-filters-no-context"><a class="anchor" href="faq.html#appendix-faq-no-filters-no-context"></a>I have a user who has definitely been authenticated, but when I try to access the SecurityContextHolder during some requests, the Authentication is null.</h3>
<div class="paragraph">
<p>Why can&#8217;t I see the user information?</p>
</div>
<div class="paragraph">
<p>If you have excluded the request from the security filter chain using the attribute <code>filters='none'</code> in the <code>&lt;intercept-url&gt;</code> element that matches the URL pattern, then the <code>SecurityContextHolder</code> will not be populated for that request.
Check the debug log to see whether the request is passing through the filter chain.
(You are reading the debug log, right?).</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-method-security-with-taglib"><a class="anchor" href="faq.html#appendix-faq-method-security-with-taglib"></a>The authorize JSP Tag doesn&#8217;t respect my method security annotations when using the URL attribute.</h3>
<div class="paragraph">
<p>Method security will not hide links when using the <code>url</code> attribute in <code>&lt;sec:authorize&gt;</code> because we cannot readily reverse engineer what URL is mapped to what controller endpoint as controllers can rely on headers, current user, etc to determine what method to invoke.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="appendix-faq-architecture"><a class="anchor" href="faq.html#appendix-faq-architecture"></a>Spring Security Architecture Questions</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="faq.html#appendix-faq-where-is-class-x">How do I know which package class X is in?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-namespace-to-bean-mapping">How do the namespace elements map to conventional bean configurations?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-role-prefix">What does "ROLE_" mean and why do I need it on my role names?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-what-dependencies">How do I know which dependencies to add to my application to work with Spring Security?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-apacheds-deps">What dependencies are needed to run an embedded ApacheDS LDAP server?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-what-is-userdetailservice">What is a UserDetailsService and do I need one?</a></p>
</li>
</ol>
</div>
<div class="sect2">
<h3 id="appendix-faq-where-is-class-x"><a class="anchor" href="faq.html#appendix-faq-where-is-class-x"></a>How do I know which package class X is in?</h3>
<div class="paragraph">
<p>The best way of locating classes is by installing the Spring Security source in your IDE. The distribution includes source jars for each of the modules the project is divided up into.
Add these to your project source path and you can navigate directly to Spring Security classes (<code>Ctrl-Shift-T</code> in Eclipse). This also makes debugging easier and allows you to troubleshoot exceptions by looking directly at the code where they occur to see what&#8217;s going on there.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-namespace-to-bean-mapping"><a class="anchor" href="faq.html#appendix-faq-namespace-to-bean-mapping"></a>How do the namespace elements map to conventional bean configurations?</h3>
<div class="paragraph">
<p>There is a general overview of what beans are created by the namespace in the namespace appendix of the reference guide.
There is also a detailed blog article called "Behind the Spring Security Namespace" on <a href="https://spring.io/blog/2010/03/06/behind-the-spring-security-namespace/">blog.springsource.com</a>. If want to know the full details then the code is in the <code>spring-security-config</code> module within the Spring Security 3.0 distribution.
You should probably read the chapters on namespace parsing in the standard Spring Framework reference documentation first.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-role-prefix"><a class="anchor" href="faq.html#appendix-faq-role-prefix"></a>What does "ROLE_" mean and why do I need it on my role names?</h3>
<div class="paragraph">
<p>Spring Security has a voter-based architecture which means that an access decision is made by a series of <code>AccessDecisionVoter</code>s.
The voters act on the "configuration attributes" which are specified for a secured resource (such as a method invocation). With this approach, not all attributes may be relevant to all voters and a voter needs to know when it should ignore an attribute (abstain) and when it should vote to grant or deny access based on the attribute value.
The most common voter is the <code>RoleVoter</code> which by default votes whenever it finds an attribute with the "ROLE_" prefix.
It makes a simple comparison of the attribute (such as "ROLE_USER") with the names of the authorities which the current user has been assigned.
If it finds a match (they have an authority called "ROLE_USER"), it votes to grant access, otherwise it votes to deny access.</p>
</div>
<div class="paragraph">
<p>The prefix can be changed by setting the <code>rolePrefix</code> property of <code>RoleVoter</code>. If you only need to use roles in your application and have no need for other custom voters, then you can set the prefix to a blank string, in which case the <code>RoleVoter</code> will treat all attributes as roles.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-what-dependencies"><a class="anchor" href="faq.html#appendix-faq-what-dependencies"></a>How do I know which dependencies to add to my application to work with Spring Security?</h3>
<div class="paragraph">
<p>It will depend on what features you are using and what type of application you are developing.
With Spring Security 3.0, the project jars are divided into clearly distinct areas of functionality, so it is straightforward to work out which Spring Security jars you need from your application requirements.
All applications will need the <code>spring-security-core</code> jar.
If you&#8217;re developing a web application, you need the <code>spring-security-web</code> jar.
If you&#8217;re using security namespace configuration you need the <code>spring-security-config</code> jar, for LDAP support you need the <code>spring-security-ldap</code> jar and so on.</p>
</div>
<div class="paragraph">
<p>For third-party jars the situation isn&#8217;t always quite so obvious.
A good starting point is to copy those from one of the pre-built sample applications WEB-INF/lib directories.
For a basic application, you can start with the tutorial sample.
If you want to use LDAP, with an embedded test server, then use the LDAP sample as a starting point.
The reference manual also includes <a href="https://docs.spring.io/spring-security/site/docs/current/reference/html5/#modules">an appendix</a> listing the first-level dependencies for each Spring Security module with some information on whether they are optional and what they are required for.</p>
</div>
<div class="paragraph">
<p>If you are building your project with maven, then adding the appropriate Spring Security modules as dependencies to your pom.xml will automatically pull in the core jars that the framework requires.
Any which are marked as "optional" in the Spring Security POM files will have to be added to your own pom.xml file if you need them.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-apacheds-deps"><a class="anchor" href="faq.html#appendix-faq-apacheds-deps"></a>What dependencies are needed to run an embedded ApacheDS LDAP server?</h3>
<div class="paragraph">
<p>If you are using Maven, you need to add the following to your pom dependencies:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">&lt;dependency&gt;
		&lt;groupId&gt;org.apache.directory.server&lt;/groupId&gt;
		&lt;artifactId&gt;apacheds-core&lt;/artifactId&gt;
		&lt;version&gt;1.5.5&lt;/version&gt;
		&lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
		&lt;groupId&gt;org.apache.directory.server&lt;/groupId&gt;
		&lt;artifactId&gt;apacheds-server-jndi&lt;/artifactId&gt;
		&lt;version&gt;1.5.5&lt;/version&gt;
		&lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The other required jars should be pulled in transitively.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-what-is-userdetailservice"><a class="anchor" href="faq.html#appendix-faq-what-is-userdetailservice"></a>What is a UserDetailsService and do I need one?</h3>
<div class="paragraph">
<p><code>UserDetailsService</code> is a DAO interface for loading data that is specific to a user account.
It has no other function other to load that data for use by other components within the framework.
It is not responsible for authenticating the user.
Authenticating a user with a username/password combination is most commonly performed by the <code>DaoAuthenticationProvider</code>, which is injected with a <code>UserDetailsService</code> to allow it to load the password (and other data) for a user in order to compare it with the submitted value.
Note that if you are using LDAP, <a href="faq.html#appendix-faq-ldap-authentication">this approach may not work</a>.</p>
</div>
<div class="paragraph">
<p>If you want to customize the authentication process then you should implement <code>AuthenticationProvider</code> yourself.
See this <a href="https://spring.io/blog/2010/08/02/spring-security-in-google-app-engine/"> blog article</a> for an example integrating Spring Security authentication with Google App Engine.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="appendix-faq-howto"><a class="anchor" href="faq.html#appendix-faq-howto"></a>Common "Howto" Requests</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="faq.html#appendix-faq-extra-login-fields">I need to login in with more information than just the username.</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-matching-url-fragments">How do I apply different intercept-url constraints where only the fragment value of the requested URLs differs (e.g./foo#bar and /foo#blah?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-request-details-in-user-service">How do I access the user&#8217;s IP Address (or other web-request data) in a UserDetailsService?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-access-session-from-user-service">How do I access the HttpSession from a UserDetailsService?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-password-in-user-service">How do I access the user&#8217;s password in a UserDetailsService?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-dynamic-url-metadata">How do I define the secured URLs within an application dynamically?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-ldap-authorities">How do I authenticate against LDAP but load user roles from a database?</a></p>
</li>
<li>
<p><a href="faq.html#appendix-faq-namespace-post-processor">I want to modify the property of a bean that is created by the namespace, but there is nothing in the schema to support it.</a></p>
</li>
</ol>
</div>
<div class="sect2">
<h3 id="appendix-faq-extra-login-fields"><a class="anchor" href="faq.html#appendix-faq-extra-login-fields"></a>I need to login in with more information than just the username.</h3>
<div class="paragraph">
<p>How do I add support for extra login fields (e.g.
a company name)?</p>
</div>
<div class="paragraph">
<p>This question comes up repeatedly in the Spring Security forum so you will find more information there by searching the archives (or through google).</p>
</div>
<div class="paragraph">
<p>The submitted login information is processed by an instance of <code>UsernamePasswordAuthenticationFilter</code>. You will need to customize this class to handle the extra data field(s). One option is to use your own customized authentication token class (rather than the standard <code>UsernamePasswordAuthenticationToken</code>), another is simply to concatenate the extra fields with the username (for example, using a ":" as the separator) and pass them in the username property of <code>UsernamePasswordAuthenticationToken</code>.</p>
</div>
<div class="paragraph">
<p>You will also need to customize the actual authentication process.
If you are using a custom authentication token class, for example, you will have to write an <code>AuthenticationProvider</code> to handle it (or extend the standard <code>DaoAuthenticationProvider</code>). If you have concatenated the fields, you can implement your own <code>UserDetailsService</code> which splits them up and loads the appropriate user data for authentication.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-matching-url-fragments"><a class="anchor" href="faq.html#appendix-faq-matching-url-fragments"></a>How do I apply different intercept-url constraints where only the fragment value of the requested URLs differs (e.g./foo#bar and /foo#blah?</h3>
<div class="paragraph">
<p>You can&#8217;t do this, since the fragment is not transmitted from the browser to the server.
The URLs above are identical from the server&#8217;s perspective.
This is a common question from GWT users.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-request-details-in-user-service"><a class="anchor" href="faq.html#appendix-faq-request-details-in-user-service"></a>How do I access the user&#8217;s IP Address (or other web-request data) in a UserDetailsService?</h3>
<div class="paragraph">
<p>Obviously you can&#8217;t (without resorting to something like thread-local variables) since the only information supplied to the interface is the username.
Instead of implementing <code>UserDetailsService</code>, you should implement <code>AuthenticationProvider</code> directly and extract the information from the supplied <code>Authentication</code> token.</p>
</div>
<div class="paragraph">
<p>In a standard web setup, the <code>getDetails()</code> method on the <code>Authentication</code> object will return an instance of <code>WebAuthenticationDetails</code>. If you need additional information, you can inject a custom <code>AuthenticationDetailsSource</code> into the authentication filter you are using.
If you are using the namespace, for example with the <code>&lt;form-login&gt;</code> element, then you should remove this element and replace it with a <code>&lt;custom-filter&gt;</code> declaration pointing to an explicitly configured <code>UsernamePasswordAuthenticationFilter</code>.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-access-session-from-user-service"><a class="anchor" href="faq.html#appendix-faq-access-session-from-user-service"></a>How do I access the HttpSession from a UserDetailsService?</h3>
<div class="paragraph">
<p>You can&#8217;t, since the <code>UserDetailsService</code> has no awareness of the servlet API. If you want to store custom user data, then you should customize the <code>UserDetails</code> object which is returned.
This can then be accessed at any point, via the thread-local <code>SecurityContextHolder</code>. A call to <code>SecurityContextHolder.getContext().getAuthentication().getPrincipal()</code> will return this custom object.</p>
</div>
<div class="paragraph">
<p>If you really need to access the session, then it must be done by customizing the web tier.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-password-in-user-service"><a class="anchor" href="faq.html#appendix-faq-password-in-user-service"></a>How do I access the user&#8217;s password in a UserDetailsService?</h3>
<div class="paragraph">
<p>You can&#8217;t (and shouldn&#8217;t). You are probably misunderstanding its purpose.
See "<a href="faq.html#appendix-faq-what-is-userdetailservice">What is a UserDetailsService?</a>" above.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-dynamic-url-metadata"><a class="anchor" href="faq.html#appendix-faq-dynamic-url-metadata"></a>How do I define the secured URLs within an application dynamically?</h3>
<div class="paragraph">
<p>People often ask about how to store the mapping between secured URLs and security metadata attributes in a database, rather than in the application context.</p>
</div>
<div class="paragraph">
<p>The first thing you should ask yourself is if you really need to do this.
If an application requires securing, then it also requires that the security be tested thoroughly based on a defined policy.
It may require auditing and acceptance testing before being rolled out into a production environment.
A security-conscious organization should be aware that the benefits of their diligent testing process could be wiped out instantly by allowing the security settings to be modified at runtime by changing a row or two in a configuration database.
If you have taken this into account (perhaps using multiple layers of security within your application) then Spring Security allows you to fully customize the source of security metadata.
You can make it fully dynamic if you choose.</p>
</div>
<div class="paragraph">
<p>Both method and web security are protected by subclasses of <code>AbstractSecurityInterceptor</code> which is configured with a <code>SecurityMetadataSource</code> from which it obtains the metadata for a particular method or filter invocation.
For web security, the interceptor class is <code>FilterSecurityInterceptor</code> and it uses the marker interface <code>FilterInvocationSecurityMetadataSource</code>. The "secured object" type it operates on is a <code>FilterInvocation</code>. The default implementation which is used (both in the namespace <code>&lt;http&gt;</code> and when configuring the interceptor explicitly, stores the list of URL patterns and their corresponding list of "configuration attributes" (instances of <code>ConfigAttribute</code>) in an in-memory map.</p>
</div>
<div class="paragraph">
<p>To load the data from an alternative source, you must be using an explicitly declared security filter chain (typically Spring Security&#8217;s <code>FilterChainProxy</code>) in order to customize the <code>FilterSecurityInterceptor</code> bean.
You can&#8217;t use the namespace.
You would then implement <code>FilterInvocationSecurityMetadataSource</code> to load the data as you please for a particular <code>FilterInvocation</code> <sup class="footnote">[<a id="_footnoteref_1" class="footnote" href="faq.html#_footnotedef_1" title="View footnote.">1</a>]</sup>. A very basic outline would look something like this:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock primary">
<div class="title">Java</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">	public class MyFilterSecurityMetadataSource implements FilterInvocationSecurityMetadataSource {

		public List&lt;ConfigAttribute&gt; getAttributes(Object object) {
			FilterInvocation fi = (FilterInvocation) object;
				String url = fi.getRequestUrl();
				String httpMethod = fi.getRequest().getMethod();
				List&lt;ConfigAttribute&gt; attributes = new ArrayList&lt;ConfigAttribute&gt;();

				// Lookup your database (or other source) using this information and populate the
				// list of attributes

				return attributes;
		}

		public Collection&lt;ConfigAttribute&gt; getAllConfigAttributes() {
			return null;
		}

		public boolean supports(Class&lt;?&gt; clazz) {
			return FilterInvocation.class.isAssignableFrom(clazz);
		}
	}</code></pre>
</div>
</div>
<div class="listingblock secondary">
<div class="title">Kotlin</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-kotlin hljs" data-lang="kotlin">class MyFilterSecurityMetadataSource : FilterInvocationSecurityMetadataSource {
    override fun getAttributes(securedObject: Any): List&lt;ConfigAttribute&gt; {
        val fi = securedObject as FilterInvocation
        val url = fi.requestUrl
        val httpMethod = fi.request.method

        // Lookup your database (or other source) using this information and populate the
        // list of attributes
        return ArrayList()
    }

    override fun getAllConfigAttributes(): Collection&lt;ConfigAttribute&gt;? {
        return null
    }

    override fun supports(clazz: Class&lt;*&gt;): Boolean {
        return FilterInvocation::class.java.isAssignableFrom(clazz)
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>For more information, look at the code for <code>DefaultFilterInvocationSecurityMetadataSource</code>.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-ldap-authorities"><a class="anchor" href="faq.html#appendix-faq-ldap-authorities"></a>How do I authenticate against LDAP but load user roles from a database?</h3>
<div class="paragraph">
<p>The <code>LdapAuthenticationProvider</code> bean (which handles normal LDAP authentication in Spring Security) is configured with two separate strategy interfaces, one which performs the authentication and one which loads the user authorities, called <code>LdapAuthenticator</code> and <code>LdapAuthoritiesPopulator</code> respectively.
The <code>DefaultLdapAuthoritiesPopulator</code> loads the user authorities from the LDAP directory and has various configuration parameters to allow you to specify how these should be retrieved.</p>
</div>
<div class="paragraph">
<p>To use JDBC instead, you can implement the interface yourself, using whatever SQL is appropriate for your schema:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock primary">
<div class="title">Java</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">	public class MyAuthoritiesPopulator implements LdapAuthoritiesPopulator {
		@Autowired
		JdbcTemplate template;

		List&lt;GrantedAuthority&gt; getGrantedAuthorities(DirContextOperations userData, String username) {
			return template.query("select role from roles where username = ?",
					new String[] {username},
					new RowMapper&lt;GrantedAuthority&gt;() {
				 /**
				 *  We're assuming here that you're using the standard convention of using the role
				 *  prefix "ROLE_" to mark attributes which are supported by Spring Security's RoleVoter.
				 */
				@Override
				public GrantedAuthority mapRow(ResultSet rs, int rowNum) throws SQLException {
					return new SimpleGrantedAuthority("ROLE_" + rs.getString(1));
				}
			});
		}
	}</code></pre>
</div>
</div>
<div class="listingblock secondary">
<div class="title">Kotlin</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-kotlin hljs" data-lang="kotlin">class MyAuthoritiesPopulator : LdapAuthoritiesPopulator {
    @Autowired
    lateinit var template: JdbcTemplate

    override fun getGrantedAuthorities(userData: DirContextOperations, username: String): MutableList&lt;GrantedAuthority?&gt; {
        return template.query("select role from roles where username = ?",
            arrayOf(username)
        ) { rs, _ -&gt;
            /**
             * We're assuming here that you're using the standard convention of using the role
             * prefix "ROLE_" to mark attributes which are supported by Spring Security's RoleVoter.
             */
            SimpleGrantedAuthority("ROLE_" + rs.getString(1))
        }
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>You would then add a bean of this type to your application context and inject it into the <code>LdapAuthenticationProvider</code>. This is covered in the section on configuring LDAP using explicit Spring beans in the LDAP chapter of the reference manual.
Note that you can&#8217;t use the namespace for configuration in this case.
You should also consult the Javadoc for the relevant classes and interfaces.</p>
</div>
</div>
<div class="sect2">
<h3 id="appendix-faq-namespace-post-processor"><a class="anchor" href="faq.html#appendix-faq-namespace-post-processor"></a>I want to modify the property of a bean that is created by the namespace, but there is nothing in the schema to support it.</h3>
<div class="paragraph">
<p>What can I do short of abandoning namespace use?</p>
</div>
<div class="paragraph">
<p>The namespace functionality is intentionally limited, so it doesn&#8217;t cover everything that you can do with plain beans.
If you want to do something simple, like modify a bean, or inject a different dependency, you can do this by adding a <code>BeanPostProcessor</code> to your configuration.
More information can be found in the <a href="https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#beans-factory-extension-bpp">Spring Reference Manual</a>. In order to do this, you need to know a bit about which beans are created, so you should also read the blog article in the above question on <a href="faq.html#appendix-faq-namespace-to-bean-mapping">how the namespace maps to Spring beans</a>.</p>
</div>
<div class="paragraph">
<p>Normally, you would add the functionality you require to the <code>postProcessBeforeInitialization</code> method of <code>BeanPostProcessor</code>. Let&#8217;s say that you want to customize the <code>AuthenticationDetailsSource</code> used by the <code>UsernamePasswordAuthenticationFilter</code>, (created by the <code>form-login</code> element). You want to extract a particular header called <code>CUSTOM_HEADER</code> from the request and make use of it while authenticating the user.
The processor class would look like this:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock primary">
<div class="title">Java</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class CustomBeanPostProcessor implements BeanPostProcessor {

		public Object postProcessAfterInitialization(Object bean, String name) {
				if (bean instanceof UsernamePasswordAuthenticationFilter) {
						System.out.println("********* Post-processing " + name);
						((UsernamePasswordAuthenticationFilter)bean).setAuthenticationDetailsSource(
										new AuthenticationDetailsSource() {
												public Object buildDetails(Object context) {
														return ((HttpServletRequest)context).getHeader("CUSTOM_HEADER");
												}
										});
				}
				return bean;
		}

		public Object postProcessBeforeInitialization(Object bean, String name) {
				return bean;
		}
}</code></pre>
</div>
</div>
<div class="listingblock secondary">
<div class="title">Kotlin</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-kotlin hljs" data-lang="kotlin">class CustomBeanPostProcessor : BeanPostProcessor {
    override fun postProcessAfterInitialization(bean: Any, name: String): Any {
        if (bean is UsernamePasswordAuthenticationFilter) {
            println("********* Post-processing $name")
            bean.setAuthenticationDetailsSource(
                AuthenticationDetailsSource&lt;HttpServletRequest, Any?&gt; { context -&gt; context.getHeader("CUSTOM_HEADER") })
        }
        return bean
    }

    override fun postProcessBeforeInitialization(bean: Any, name: String?): Any {
        return bean
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>You would then register this bean in your application context.
Spring will automatically invoke it on the beans defined in the application context.</p>
</div>
</div>
</div>
</div>
<div id="footnotes">
<hr>
<div class="footnote" id="_footnotedef_1">
<a href="faq.html#_footnoteref_1">1</a>. The <code>FilterInvocation</code> object contains the <code>HttpServletRequest</code>, so you can obtain the URL or any other relevant information on which to base your decision on what the list of returned attributes will contain.
</div>
</div>
<nav class="pagination">
<span class="prev"><a href="namespace/websocket.html">WebSocket Security</a></span>
<span class="next"><a href="../../reactive/index.html">Reactive Applications</a></span>
</nav>
</article>
</div>
</main>
</div>
<footer class="footer flex">
<div id="spring-links flex">
<img id="springlogo" src="../../../_/img/spring-logo.svg" alt="Spring">
<p class="smallest antialiased">© <script>var d = new Date();
        document.write(d.getFullYear());</script> <a href="https://www.vmware.com/">VMware</a>, Inc. or its affiliates. <a href="https://www.vmware.com/help/legal.html">Terms of Use</a> • <a href="https://www.vmware.com/help/privacy.html" rel="noopener noreferrer">Privacy</a> • <a href="https://spring.io/trademarks">Trademark Guidelines</a> <span id="thank-you-mobile">• <a href="https://spring.io/thank-you">Thank you</a></span> • <a href="https://www.vmware.com/help/privacy/california-privacy-rights.html">Your California Privacy Rights</a> • <a class="ot-sdk-show-settings">Cookie Settings</a> <span id="teconsent"></span></p>
<p class="smallest antialiased">Apache®, Apache Tomcat®, Apache Kafka®, Apache Cassandra&trade;, and Apache Geode&trade; are trademarks or registered trademarks of the Apache Software Foundation in the United States and/or other countries. Java&trade;, Java&trade; SE, Java&trade; EE, and OpenJDK&trade; are trademarks of Oracle and/or its affiliates. Kubernetes® is a registered trademark of the Linux Foundation in the United States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other countries. Windows® and Microsoft® Azure are registered trademarks of Microsoft Corporation. “AWS” and “Amazon Web Services” are trademarks or registered trademarks of Amazon.com Inc. or its affiliates. All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes. Other names may be trademarks of their respective owners.</p>
</div>
<div id="social-icons" class="flex jc-between">
<a href="https://www.youtube.com/user/SpringSourceDev" title="Youtube"><svg id="youtube-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><circle class="cls-1" cx="20" cy="20" r="20" /><path class="cls-2" d="M30.91,14.53a2.89,2.89,0,0,0-2-2C27.12,12,20,12,20,12s-7.12,0-8.9.47a2.9,2.9,0,0,0-2,2A30.56,30.56,0,0,0,8.63,20a30.44,30.44,0,0,0,.46,5.47,2.89,2.89,0,0,0,2,2C12.9,28,20,28,20,28s7.12,0,8.9-.47a2.87,2.87,0,0,0,2-2A30.56,30.56,0,0,0,31.37,20,28.88,28.88,0,0,0,30.91,14.53ZM17.73,23.41V16.59L23.65,20Z" /></svg></a>
<a href="https://github.com/spring-projects" title="Github"><svg id="github-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 75.93 75.93"><path class="cls-1" d="M38,0a38,38,0,1,0,38,38A38,38,0,0,0,38,0Z" /></g><path class="cls-2" d="M38,15.59A22.95,22.95,0,0,0,30.71,60.3c1.15.21,1.57-.5,1.57-1.11s0-2,0-3.9c-6.38,1.39-7.73-3.07-7.73-3.07A6.09,6.09,0,0,0,22,48.86c-2.09-1.42.15-1.39.15-1.39a4.81,4.81,0,0,1,3.52,2.36c2,3.5,5.37,2.49,6.67,1.91a4.87,4.87,0,0,1,1.46-3.07c-5.09-.58-10.45-2.55-10.45-11.34a8.84,8.84,0,0,1,2.36-6.15,8.29,8.29,0,0,1,.23-6.07s1.92-.62,6.3,2.35a21.82,21.82,0,0,1,11.49,0c4.38-3,6.3-2.35,6.3-2.35a8.29,8.29,0,0,1,.23,6.07,8.84,8.84,0,0,1,2.36,6.15c0,8.81-5.37,10.75-10.48,11.32a5.46,5.46,0,0,1,1.56,4.25c0,3.07,0,5.54,0,6.29s.42,1.33,1.58,1.1A22.94,22.94,0,0,0,38,15.59Z" /></svg></a>
<a href="https://twitter.com/springcentral" title="Twitter"><svg id="twitter-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 75.93 75.93"><circle class="cls-1" cx="37.97" cy="37.97" r="37.97" /><path id="Twitter-2" data-name="Twitter" class="cls-2" d="M55.2,22.73a15.43,15.43,0,0,1-4.88,1.91,7.56,7.56,0,0,0-5.61-2.49A7.78,7.78,0,0,0,37,30a7.56,7.56,0,0,0,.2,1.79,21.63,21.63,0,0,1-15.84-8.23,8,8,0,0,0,2.37,10.52,7.66,7.66,0,0,1-3.48-1v.09A7.84,7.84,0,0,0,26.45,41a7.54,7.54,0,0,1-2,.28A7.64,7.64,0,0,1,23,41.09a7.71,7.71,0,0,0,7.18,5.47,15.21,15.21,0,0,1-9.55,3.37,15.78,15.78,0,0,1-1.83-.11,21.41,21.41,0,0,0,11.78,3.54c14.13,0,21.86-12,21.86-22.42,0-.34,0-.68,0-1a15.67,15.67,0,0,0,3.83-4.08,14.9,14.9,0,0,1-4.41,1.24A7.8,7.8,0,0,0,55.2,22.73Z" /></svg></a>
</div>
</footer>
<script src="../../../_/js/site.js"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
<script async src="../../../_/js/vendor/tabs.js"></script>
<script src="../../../_/js/vendor/switchtheme.js"></script>
<script src="../../../_/js/vendor/docsearch.min.js"></script>

<script>
var search = docsearch({
  appId: '244V8V9FGG',
  apiKey: '82c7ead946afbac3cf98c32446154691',
  indexName: 'security-docs',
  inputSelector: '#search-input',
  autocompleteOptions: { hint: false, keyboardShortcuts: ['s'] },
  algoliaOptions: { hitsPerPage: 10 }
}).autocomplete
search.on('autocomplete:closed', function () { search.autocomplete.setVal() })
</script>
<script>if (window.parent == window) {(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-2728886-23', 'auto', {'siteSpeedSampleRate': 100});ga('send', 'pageview');}</script><script defer src="https://static.cloudflareinsights.com/beacon.min.js/v652eace1692a40cfa3763df669d7439c1639079717194" integrity="sha512-Gi7xpJR8tSkrpF7aordPZQlW2DLtzUlZcumS8dMQjwDHEnw9I7ZLyiOj/6tZStRBGtGgN6ceN6cMH8z7etPGlw==" data-cf-beacon='{"rayId":"702e38913d6996ab","token":"bffcb8a918ae4755926f76178bfbd26b","version":"2021.12.0","si":100}' crossorigin="anonymous"></script>
</body>
</html>
